home *** CD-ROM | disk | FTP | other *** search
- Path: newsbf02.news.aol.com!not-for-mail
- From: simpsondg@aol.com (SimpsonDG)
- Newsgroups: comp.lang.c
- Subject: gets() question
- Date: 7 Jan 1996 11:31:11 -0500
- Organization: America Online, Inc. (1-800-827-6364)
- Sender: root@newsbf02.news.aol.com
- Message-ID: <4cosgf$rir@newsbf02.news.aol.com>
- Reply-To: simpsondg@aol.com (SimpsonDG)
- NNTP-Posting-Host: newsbf02.mail.aol.com
-
- Can any of you C gurus out there help me with this? I have a problem with
- gets() that I don't understand. The program below will successfully input
- the string s[0], but will simply ignore the gets() that inputs s[1] and
- goes on to ask for i[1]. What's the deal? A little experimenting seems
- to indicate that the problem arises when I have a gets() following a
- scanf() -- e.g., a program using only gets() or only scanf() works fine.
-
- David Simpson
-
- --------------------------------------------------------------------------
- -------------------
-
- #include "stdio.h"
-
- void main(void)
- {
- int i[5];
- char s[3][10];
-
- printf ("Enter s[0]: ");
- gets (s[0]);
-
- printf ("Enter i[0]]: ");
- scanf ("%d",&i[0]);
-
- printf ("Enter s[1]: ");
- gets (s[1]); /* this gets() doesn't wait for input */
-
- printf ("Enter i[1]]: ");
- scanf ("%d",&i[1]);
- }
-